package org.coke.provider.impl;

import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.protocol.rest.support.ContentType;
import org.coke.interfaces.UserService;
import org.springframework.stereotype.Service;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

/**
 * @author weimin
 * @date 2024/4/4
 * @description
 */
@Path("/users")
@Produces({ContentType.APPLICATION_JSON_UTF_8})
@Consumes({ContentType.APPLICATION_JSON_UTF_8})
@Service
@DubboService
public class UserServiceImpl implements UserService {

    @GET
    @Path("/getUserName")
    @Override
    public String getUserName() {
        return "provider";
    }

    /**
     * 演示 tri协议流式调用
     * @param name
     * @param observer
     * @throws InterruptedException
     */
    @Override
    public void service(String name, StreamObserver<String> observer) throws InterruptedException {
        System.out.println("接收到数据:"+name);
        observer.onNext("发送数据一");
        Thread.sleep(30000);
        observer.onNext("发送数据二");
        observer.onNext("发送数据三");
        observer.onCompleted();
    }
}
